from rest_framework_jwt.utils import jwt_payload_handler
from rest_framework_jwt.utils import jwt_response_payload_handler

def user_payload_handler(user):
    payload = jwt_payload_handler(user)
    # 在字典中添加属性
    payload['mobile'] = user.mobile
    # 从字典中删除email属性
    if 'email' in payload:
        del payload['email']
    # 返回删除和添加的payload
    return payload

def user_response_handler(token, user=None, request=None):
    return {
        'token': token,
        'id': user.id,
        'username': user.username
    }